<?php

/**
 * gallery actions.
 *
 * @package    videosurv
 * @subpackage gallery
 * @author     Mina Gerges
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class video_processingActions extends sfActions
{

    /**
     * action execute before any action
     */
    public function preExecute()
    {
        $this->user = $this->getUser()->getAttribute('user');
        $this->companyData = $this->getUser()->getAttribute('company');
    }

    public function executeRendervideo(sfWebRequest $request)
    {
        $_video_id = Video::decryptVideoId($request->getParameter('vid'));
        $this->forward404Unless($_video = Doctrine_Core::getTable('Video')->findOneById($_video_id));

        $_type = $request->getParameter('type');
        if($_type == 'puv') // render video using Public Url Video
        {
            $_camera_id = Camera::decryptCameraId($request->getParameter('c'));
            $_company_id = Company::decryptCompanyId($request->getParameter('com'));
        }
        else
        {
            Check::CheckSharingVideo($this, $_video);
            $_camera_id = $_video->camera_id;
            $_company_id = $this->companyData['id'];
        }
        //if(sfContext::getInstance()->getUser()->isAuthenticated())
        //$_path = '/home/mina/NetBeansProjects/videosurv/gallery/videos/3/28/11307969578.flv';
        $_path = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('app_dir_videos') . '/' . $_company_id . '/' . $_camera_id . '/' . $_video->path . '.' . sfConfig::get('app_video_format');
//        echo $_path;
//        exit;
        $response = $this->getResponse();
        $response = $this->getResponse();
        $response->clearHttpHeaders();
        $response->setContentType('Content-type: video/' . sfConfig::get('app_video_format'));
        $response->setHttpHeader('Content-Disposition', 'inline;filename=');
        $response->setContent(readfile($_path));
        $this->setLayout(false);
        return sfView::NONE;
    }

    function doFlush()
    {
        if(ob_get_length())
        {
            ob_flush();
            flush();
            ob_end_flush();
        }
        ob_start();
    }

}
